c++语言中“->”是什么意思!

来源:百度知道 编辑:UC知道 时间:2024/06/29 20:59:06

是结构体和类指针访问时用的

struct student
{int age;
int grade
}stu,*p;
p=&stu;//p指向stu变量
则用p访问age为 p->age=20;
这样就为stu的age赋值为20了

class A
{
int m;
int n;
}

A a, *p;
p=&a;

a.m 等同 p->m
a.n 等同 p->n